package com.example.huiyun.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.huiyun.R;

import java.util.ArrayList;
import java.util.List;

public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ViewHolder> {
    private Context context;
    private List<String> imageUrls;
    private List<Integer> imageUrlsInt;
    private List<String> imageUrlsStr;

    public ImageAdapter(Context context, List<String> imageUrls) {
        this.context = context;
        this.imageUrls = imageUrls;
        imageUrlsInt = new ArrayList<>();
        imageUrlsStr = new ArrayList<>();
        imageUrlsInt.add(R.mipmap.number1);
        imageUrlsInt.add(R.mipmap.number2);
        imageUrlsInt.add(R.mipmap.number3);
        imageUrlsInt.add(R.mipmap.number4);
        imageUrlsInt.add(R.mipmap.number5);
        imageUrlsInt.add(R.mipmap.number6);
        imageUrlsInt.add(R.mipmap.number7);
        imageUrlsInt.add(R.mipmap.number8);
        imageUrlsStr.add("健康");
        imageUrlsStr.add("养生");
        imageUrlsStr.add("食疗");
        imageUrlsStr.add("戏曲");
        imageUrlsStr.add("相声");
        imageUrlsStr.add("小品");
        imageUrlsStr.add("广场舞");
        imageUrlsStr.add("经典金曲");

    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context)
                .inflate(R.layout.item_img, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        //网络图片
//        Glide.with(context)
//                .load(imageUrls.get(position))
//                .into(holder.imageView);


        int i = position + 1;
        //加载本地图片
        Glide.with(context).load(imageUrlsInt.get(position)).error(R.mipmap.number1).into(holder.imageView);

        holder.textView.setText(imageUrlsStr.get(position));
    }

    @Override
    public int getItemCount() {
        return imageUrls.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        TextView textView;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.imageView);
            textView = itemView.findViewById(R.id.tv_name);
        }
    }
}
